package com.mar.framecompress;

import java.util.EnumMap;
import java.util.Hashtable;
import java.util.Map;

import vnc.server.rfb.cache.CachedEncoderDecoder;

import com.mar.framecompress.impl.RawEncoderDecoder;
import com.mar.framecompress.impl.test.EncodeDecodeTest;
import com.mar.framecompress.impl.zlib.ZlibEncoderDecoder;

/**
 * 
 * @author mar
 */
public class EncoderRegistry {
	private Map<Encoding, IEncoder> frameEncoderStore = new EnumMap<Encoding, IEncoder>(Encoding.class);
	
	private Map<PixelFormat, IColorEncoder> colorEncoderStore = new Hashtable<PixelFormat, IColorEncoder>(); 

	
	public void registerEncoder( IEncoder encoder, Encoding type ){
		frameEncoderStore.put(type, encoder);
	}
	
	public void unregisterEncoder( Encoding type ){
		frameEncoderStore.remove(type);
	}
	
	public void registerColorEncoder( IColorEncoder encoder, PixelFormat pixelFormat ){
		colorEncoderStore.put(pixelFormat, encoder);
	}
	
	public void unregisterColorEncoder( PixelFormat pixelFormat ){
		colorEncoderStore.remove(pixelFormat);
	}

	public IEncoder get(Encoding key) {
		return frameEncoderStore.get(key);
	}

	public IColorEncoder get(PixelFormat key) {
		return colorEncoderStore.get(key);
	}

	// SINGLETON IMPL
	private static final EncoderRegistry INTANCE = new EncoderRegistry();
	private EncoderRegistry(){
		ZlibEncoderDecoder zlibEncoderDecoder = new ZlibEncoderDecoder();
		registerEncoder( zlibEncoderDecoder , Encoding.ZLIB );

		CachedEncoderDecoder cachedEncoderDecoder = new CachedEncoderDecoder();
		CompositeEncoder compositeEncoder = new CompositeEncoder( cachedEncoderDecoder, zlibEncoderDecoder );
		registerEncoder( compositeEncoder , Encoding.DEFAULT );
	};
	public static EncoderRegistry getInstance(){ return INTANCE; }
}
